package com.tony.thread;

public class OneDataThread {
    class DualData implements Runnable{
        private int data =0;
        @Override
        public void run() {
            if(Thread.currentThread().getName().contains("add")){
                data++;
            }else{
                data--;
            }
            System.out.println(Thread.currentThread().getName()+":"+data);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        OneDataThread oneDataThread = new OneDataThread();
        DualData dualData = oneDataThread.new DualData();
        Thread t1 = new Thread(dualData,"add1");
        Thread t2 = new Thread(dualData,"add2");
        Thread t3 = new Thread(dualData,"mul01");
        Thread t4 = new Thread(dualData,"mul01");
        t1.start();t1.join();t2.start();t2.join();t3.start();t3.join();t4.start();
    }
}
